﻿using System;
using System.Web;

namespace Pantry.Web.Users
{
    public partial class Users : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(Session["user"] != null)
            {
                LabelUserName.Text = Session["user"] + " - " + Session["role"];
            }
            else
            {
                Response.Redirect("~/Users/LogOn.aspx?ReturnUrl="+Request.RawUrl);
            }
            if(Session["role"].ToString() == "1")
            {
                LinkTrustRegion.Enabled = true;
                LinkTrustRegion.CssClass = "enable";
                LinkListGovOfficeRegion.Enabled = true;
                LinkListGovOfficeRegion.CssClass = "enable";
                //LinkListTypeOfBusiness.Enabled = true;
                //LinkListTypeOfBusiness.CssClass = "enable";
                LinkViewListContact.Enabled = true;
                LinkViewListContact.CssClass = "enable";
                //LinkCreateContact.Enabled = true;
                //LinkCreateContact.CssClass = "enable";
                LinkListPrimese.Enabled = true;
                LinkListPrimese.CssClass = "enable";
                LinkFacility.Enabled = true;
                LinkFacility.CssClass = "enable";
                //LinkListAddress.Enabled = true;
                //LinkListAddress.CssClass = "enable";
                PanelOrganisation.Visible = false;
            }
            else
            {
                LinkTrustRegion.Enabled = true;
                LinkTrustRegion.CssClass = "enable";
                //LinkListTypeOfBusiness.Enabled = true;
                //LinkListTypeOfBusiness.CssClass = "enable";
                LinkViewListContact.Enabled = true;
                LinkViewListContact.CssClass = "enable";
                //LinkCreateContact.Enabled = true;
                //LinkCreateContact.CssClass = "enable";
                LinkProgramme.Enabled = true;
                LinkProgramme.CssClass = "enable";
                LinkListOrganisation.Enabled = true;
                LinkListOrganisation.CssClass = "enable";
                //LinkListOrganisation1.Enabled = true;
                //LinkListOrganisation1.CssClass = "enable";
                LinkListService.Enabled = true;
                LinkListService.CssClass = "enable";
                //LinkListAddress.Enabled = true;
                //LinkListAddress.CssClass = "enable";
                
            }
        }
        protected void ButtonLogoutClick(object sender,EventArgs e)
        {
            Session.Abandon();
            HttpCookie httpCookie = Request.Cookies["CookieLogOn"];
            if (httpCookie != null)
            {
                httpCookie.Expires = DateTime.Now.AddDays(-1d);
                Response.Cookies.Add(httpCookie);
            }
            Response.Redirect(Request.RawUrl);
        }
    }
}
